package fr.bitstrip.sitn.dao;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import fr.bitstrip.sitn.model.ImageFinale;
@Repository("ImageFinaleDAO")
@Transactional
public class ImageFinaleDAO {
	@Autowired
	private SessionFactory sessionFactory;
	
	public Session getSession() {
		return sessionFactory.getCurrentSession();
	}
 
    public void setSessionFactory(SessionFactory sessionFactory) {
    	this.sessionFactory = sessionFactory;
    }
    @Transactional(readOnly = true)
    public List<ImageFinale> get(){
            return (List<ImageFinale>) getSession().createQuery("from ImageFinale").list();
    }

    public ImageFinale get(String id) {
         Criteria criteria = getSession().createCriteria(ImageFinale.class).add(Restrictions.like("id", id));
         ImageFinale imageFinale = (ImageFinale) criteria.uniqueResult();
         return imageFinale;
    }
    
    @Transactional(readOnly = false, propagation = Propagation.REQUIRED)
	public void save(ImageFinale imagefinale) {
		getSession().saveOrUpdate(imagefinale);
	}

}
